<?php 
function ListSitemap()
{
    global $dbsql,$language;
    
    $sql_select = "select iId,cUrlString,cName,cType from tblcategory where iParentId=0 
    and iStatus=1 and cLanguage='$language' order by iOrder";
    
    $rs         = $dbsql->query($sql_select);
    $return     = '<ul>';
    while($result=$dbsql->fetch_array($rs))
    {
        $link   = '/'.$result['cUrlString'];
        $return.= '<li><a href="'.$link.'"><strong>'.$result['cName'].'</strong></a></li>';
        if($result['cType']=='tourtype')
        {
            $return.=SitemapTourType($link);
        }
        else if($result['cType']=='tour')
        {
            $return.=SitemapTourChild($link);
        }
        else if($result['cType']=='location')
        {
            $return.=SitemapLocation($link,0);
        }
        else if($result['cType']=='hotel')
        {
            $return.=SitemapTourChild($link,0);
        }else
        {
            $return.=SitemapCatChild($link,$result['iId']);
        }
    }
    $return    .= '</ul>';
    return $return;
}

function SitemapTourType($urlparent)
{
    global $dbsql,$language;
    
    $sql_select = "select iId,cUrlString,cName from tbltourtype where iStatus=1 and cLanguage='$language'
                    order by iOrder";
                    
    $rs         = $dbsql->query($sql_select);
    $return     = '<ul>';
    while($result=$dbsql->fetch_array($rs))
    {
        $link   = $urlparent.'/'.$result['cUrlString'];
        $return.= '<li><a href="'.$link.'">'.$result['cName'].'</a></li>';
    }
    $return    .= '</ul>';
    return $return;
}

function SitemapTourChild($urlparent)
{
    global $dbsql,$language;
    
    $sql_select = "select iId,cUrlString,cName from tbllocation where iParentId=0 and iStatus=1 
                and cLanguage='$language' order by iOrder";
                    
    $rs         = $dbsql->query($sql_select);
    $return     = '<ul>';
    while($result=$dbsql->fetch_array($rs))
    {
        $link   = $urlparent.'/'.$result['cUrlString'];
        $return.= '<li><a href="'.$link.'">'.$result['cName'].'</a></li>';
    }
    $return    .= '</ul>';
    return $return;
}

function SitemapLocation($urlparent,$idP=0)
{
    global $dbsql,$language;
    
    $sql_select = "select iId,cUrlString,cName from tbllocation where iParentId=$idP 
                and (iParentId!=0 or iStatus=1)
                and cLanguage='$language' order by iOrder";
                   
    $rs         = $dbsql->query($sql_select);
    $return     = '<ul>';
    while($result=$dbsql->fetch_array($rs))
    {
        $link   = $urlparent.'/'.$result['cUrlString'];
        $return.= '<li><a href="'.$link.'">'.$result['cName'].'</a></li>';
        $return.= SitemapLocation($link,$result['iId']);
    }
    $return    .= '</ul>';
    return $return;
}

function SitemapCatChild($urlparent,$idP=0)
{
    global $dbsql,$language;
    
    $sql_select = "select iId,cUrlString,cName from tblcategory where iParentId=$idP and iStatus=1
                and cLanguage='$language' order by iOrder";
                   
    $rs         = $dbsql->query($sql_select);
    $return     = '<ul>';
    while($result=$dbsql->fetch_array($rs))
    {
        $link   = $urlparent.'/'.$result['cUrlString'];
        $return.= '<li><a href="'.$link.'">'.$result['cName'].'</a></li>';
        $return.= SitemapCatChild($link,$result['iId']);
    }
    $return    .= '</ul>';
    return $return;
}
?>
